package com.cloud.core.aop;

/**
* 获取用户登录信息
* Copyright: Copyright (C) 2020 DLANGEL, Inc. All rights reserved.
* Company: 大连安琪科技有限公司
* @author  dcl
* @since 2020-08-17 09:37
*/
public class SubjectContextHolder 
{
	   private static final ThreadLocal contextHolder = new ThreadLocal<>();
	    /**
	     * 设置用户
	     * @param userDto
	     */
	    public static void setSubject(UserDto userDto) {
	    	
	        contextHolder.set(userDto);
	    }

	    /**
	     * 取得用户信息
	     * @return
	     */
	    public static UserDto getSubject() 
	    {
	    	Object subjectObj=contextHolder.get();
	    	if(subjectObj!=null){
	    		  return (UserDto) subjectObj;
	    	}
	    	return null;
	    }

	    /**
	     * 清除上下文数据
	     */
	    public static void clearSubject() {
	        contextHolder.remove();
	    }
}
